package com.tiancheng.trade.payment.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.commom.core.exception.BusinessException;
import com.tiancheng.trade.commom.web.model.request.OrderPayDTO;
import com.tiancheng.trade.commom.web.model.request.VerificationRequestVO;
import com.tiancheng.trade.commom.web.model.response.VerificationOrderResponseVO;
import com.tiancheng.trade.payment.bo.notify.PayNotifyBO;
import com.tiancheng.trade.payment.channel.bo.GetUnifiedOrderResBO;
import com.tiancheng.trade.payment.channel.bo.PayResultBO;
import com.tiancheng.trade.payment.model.PaymentOrder;
import com.tiancheng.trade.payment.vo.admin.PaymentFlowQueryVo;
import com.tiancheng.trade.payment.vo.admin.res.PaymentFlowQueryResVO;
import com.tiancheng.trade.payment.vo.api.*;
import com.tiancheng.trade.commom.web.model.response.UnifiedOrderResVO;

import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;

/**
 * 支付流水服务
 *
 * @author su
 */
public interface PaymentOrderService extends IService<PaymentOrder> {

	/**
	 * 支付统一下单
	 * @param unifiedOrderVO
	 * @return
	 */
	UnifiedOrderResVO unifiedOrder(OrderPayDTO unifiedOrderVO);

	/**
	 * 支付统一下单——抵扣（免支付）
	 * @param unifiedOrderVO
	 * @return
	 */
	UnifiedOrderResVO deductionUnified(OrderPayDTO unifiedOrderVO);
	/**
	 * 根据id获取支付流水
	 *
	 * @param id
	 * @return
	 */
	PaymentOrder get(Long id);

	/**
	 * 根据id获取支付流水详情
	 *
	 * @param id
	 * @return
	 */
	PaymentFlowQueryResVO getInfo(Long id);

	/**
	 * 分页查询支付流水
	 *
	 * @param vo
	 * @return
	 */
	PageInfo findList(PaymentFlowQueryVo vo);

	/**
	 * 关闭流水
	 * @param orderVO
	 * @return
	 */
	Result<String> closeOrder(CloseOrderVO orderVO);

	/**
	 * 核销流水
	 * @param orderVO
	 * @return
	 */
	Result<VerificationOrderResponseVO> verification(VerificationRequestVO orderVO);

	/**
	 * 根据flowId获取支付流水
	 *
	 * @param flowId
	 * @return
	 */
	PaymentOrder findByPaymentFlowId(String flowId);

	/**
	 * 获取用户指定流水
	 * @param userId
	 * @param flowId
	 * @return
	 */
	PaymentOrder get(String userId, String flowId);
	/**
	 * 获取用户指定流水
	 * @param flowId
	 * @return
	 */
	PaymentOrder get(String flowId);

	/**
	 * 处理支付回调结果
	 * @param payResultBO
	 * @return
	 * @throws BusinessException
	 */
	PayNotifyBO payResult(PayResultBO payResultBO) throws BusinessException;

	/**
	 * 统计指定商户时间范围内已支付的流水总金额
	 * @param merchantCode
	 * @param startTime
	 * @param endTime
	 * @param paymentChannel
	 * @return
	 */
	long totalAmountOfMerchant(String merchantCode, LocalDateTime startTime, LocalDateTime endTime, String paymentChannel);

	/**
	 * 查询支付结果
	 *
	 * @param getUnifiedOrderVo
	 * @return
	 */
	Result<GetUnifiedOrderResBO> queryPayResult(GetUnifiedOrderVo getUnifiedOrderVo);

	/**
	 * 导出表格数据
	 *
	 * @return
	 */
	Result exportList(PaymentFlowQueryVo paymentFlowQueryVo, HttpServletResponse response) throws IOException;

	/**
	 * 苹果内购
	 * @param unifiedOrderVO
	 * @return
	 */
	UnifiedOrderResVO appleInAppPay(OrderPayDTO unifiedOrderVO);

	/**
	 * 支付单号集合
	 * @param paymentId 支付单号集合
	 * @return
	 */
	PaymentOrder querySuccessFlowByPaymentId(String paymentId);

	/**
	 * 苹果内购
	 * @param unifiedOrderVO
	 * @return
	 */
	UnifiedOrderResVO appleInAppPayV2(OrderPayDTO unifiedOrderVO);

}
